package com.example.cheng.controller;


import com.example.cheng.pojo.User;
import com.example.cheng.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//@Controller
@RestController
@Api(tags = "测试2")
@RequestMapping("/login")
public class LoginController {

    @Autowired
    UserService userService;

    @ApiOperation(value = "登录")
    @PostMapping("/login")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "账号", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "psd", value = "密码", required = true, dataType = "String")
    })
    public String login(String id, String psd){
//        System.out.println(id + psd);
        User user = userService.getById(id);
        if (user == null){
            return "查无此人";
        }
        return user.getPsd().equals(psd) ? "登录成功" + user.getName() : "密码错误";
    }

    @ApiOperation(value = "退出登录")
    @PutMapping("/outLogin")
    @ApiImplicitParam(paramType = "query", name = "id", value = "账号", required = true, dataType = "String")
    public String outLogin(String id){
        return id + "退出登录成功";
    }

}
